const router = require('koa-router')()
const koaBody = require('koa-body')();
const request = require('superagent'); //不要忘记npm instal
var config=require('../config/app.config');
const co = require('co')
module.exports = router.post('/query', koaBody, co.wrap(function*(ctx) {
    console.log(ctx.request.body);
    let reqJson= ctx.request.body;
    reqJson['orgId']=config.orgId;
    reqJson['merchantId']=config.merchantId;
    var res = yield request
    .post(config.host+'/api/cms/comments/query')
    .send(reqJson)
    .set('X-API-Key', 'foobar')
    .set('Accept', 'application/json')
    .set('Content-Type', 'application/json');
    console.log(res);
    ctx.response.body = res.body;
    //ctx.render('index', { title: 'Nunjucks', content: 'Feifeiyu yeah!' });
  })).post('/queryMany', koaBody, co.wrap(function*(ctx) {
    console.log(ctx.request.body);
    let reqJson= ctx.request.body;
    reqJson['orgId']=config.orgId;
    reqJson['merchantId']=config.merchantId;
    var res = yield request
    .post(config.host+'/api/cms/comments/queryMany')
    .send(reqJson)
    .set('X-API-Key', 'foobar')
    .set('Accept', 'application/json')
    .set('Content-Type', 'application/json');
    console.log(JSON.stringify(res.body));
    ctx.response.body = JSON.stringify(res.body);
    //ctx.render('index', { title: 'Nunjucks', content: 'Feifeiyu yeah!' });
  })).post('/add', koaBody, co.wrap(function*(ctx) {
    console.log(ctx.request.body);
    let reqJson= ctx.request.body;
    reqJson['orgId']=config.orgId;
    reqJson['merchantId']=config.merchantId;
    var res = yield request
    .post(config.host+'/api/cms/comments/add')
    .send(reqJson)
    .set('X-API-Key', 'foobar')
    .set('Accept', 'application/json')
    .set('Content-Type', 'application/json');
    console.log(res.body);
    ctx.response.body = res.body;
    //ctx.render('index', { title: 'Nunjucks', content: 'Feifeiyu yeah!' });
  }));